import java.io.File;
import java.io.IOException;

public class SimplifyPath {
    public static void main(String[] args) throws IOException {
        File test = new File("/home/user/Documents/../Pictures");

        System.out.println(test.getPath());// 返回定义时的路径
        System.out.println(test.getAbsolutePath()); // 绝对路径，但是不会处理.或者..
    }

    public String simplifyPath(String path) {
        try {
            File file = new File(path);
            // 规范化的绝对路径，会解析.或者..
            String resultPath = file.getCanonicalPath().replace("/System/Volumes/Data", "");
            if (resultPath.startsWith("/../")) {
                resultPath = new StringBuilder(resultPath).replace(0, 3, "").toString();
            }
            if(resultPath.equals("/..")){
                resultPath="/";
            }
            return resultPath;
        } catch (Exception e) {
            return "";
        }
    }
}
